package com.wn.controller;

import com.common.entity.Order;
import com.common.entity.OrderItem;
import com.common.entity.Rsp;
import com.wn.service.OrderItemService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
public class OrderItemController {

    @Autowired
    private OrderItemService  orderItemService;


    /**
     * @ClassName
     * @Description :根据订单id查询订单详情列表
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("searchOrderItemList/{orderId}")
    public Rsp searchOrderItemList(@PathVariable String orderId,
                                   @RequestHeader("token")String token){
        Rsp rsp = orderItemService.searchOrderItemList(orderId);
        return rsp;
    }

    /**
     * @ClassName
     * @Description :根据id查询订单详情
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("getOneByIdOrderItem")
    public Rsp getOneByIdOrderItem(@RequestParam("id") String id,
                                   @RequestHeader("token")String token){
         OrderItem oneById = orderItemService.getOneById(id);
        return Rsp.success(oneById);
    }

    /**
     * @ClassName
     * @Description : 批量添加订单详情
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PutMapping("addOrderItemList")
    @ApiOperation("批量添加订单详情")
    public Rsp addOrderItemList(@RequestBody List<OrderItem> orderItems,
                                @RequestHeader("token")String token){
        Rsp rsp = orderItemService.addOrderItemList(orderItems);
        return rsp;
    }

    @PostMapping("updateOrderItem")
    @ApiOperation("修改订单详情")
    public Rsp updateOrderItem(@RequestBody OrderItem orderItem,
                           @RequestHeader("token") String token){
        return orderItemService.update(orderItem);
    }

    /**
     * @ClassName
     * @Description : deleteLogical删除计划
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("deleteTrueOrderItem")
    @ApiOperation("物理删除订单详情项")
    public Rsp deleteTrueOrderItem(@RequestBody OrderItem orderItem,
                                  @RequestHeader("token") String token){
        return orderItemService.deleteOneTrue(orderItem.getId());
    }
}
